package com.xinqi.modules.sys.sensitive.word.manager.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
import com.xinqi.common.base.error.CommonErrors;
import com.xinqi.common.mybatis.data.service.impl.BaseServiceImpl;
import com.xinqi.modules.sys.sensitive.word.domain.SensitiveWordEntity;
import com.xinqi.modules.sys.sensitive.word.dto.req.SensitiveWordQueryDTO;
import com.xinqi.modules.sys.sensitive.word.dto.rsp.SensitiveWordResultDTO;
import com.xinqi.modules.sys.sensitive.word.manager.SensitiveWordManager;
import com.xinqi.modules.sys.sensitive.word.mapper.SensitiveWordMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Objects;
import java.util.Set;

/**
 * 敏感词管理表管理层实现
 *
 * @author: wenjie
 * @date: 2023/08/02
 */
@Service
@RequiredArgsConstructor
public class SensitiveWordManagerImpl extends BaseServiceImpl<SensitiveWordMapper, SensitiveWordEntity> implements SensitiveWordManager {

    /**
     * 自定义分页查询
     */
    @Override
    public Page<SensitiveWordResultDTO> findPage(Page<Object> page, SensitiveWordQueryDTO query) {
        return this.baseMapper.findPage(page, query);
    }

    /**
     * 自定义列表查询
     */
    @Override
    public List<SensitiveWordResultDTO> findList(SensitiveWordQueryDTO query) {
        return this.baseMapper.findList(query);
    }

    /**
     * 根据id查询 敏感词管理表数据
     */
    @Override
    public SensitiveWordEntity findById(Long id) {
        CommonErrors.BAD_REQUEST.check(Objects.nonNull(id), "ID不能为空");
        return getById(id);
    }

    /**
     * 根据id更新 敏感词管理表数据，重写
     */
    @Override
    public boolean updateById(SensitiveWordEntity entity) {
        return SqlHelper.retBool(getBaseMapper().updateById(entity));
    }

    /**
     * 根据id删除 敏感词管理表数据
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean deleteById(Long id) {
        CommonErrors.BAD_REQUEST.check(Objects.nonNull(id), "ID不能为空");
        return this.removeById(id);
    }

    @Override
    public Set<String> findTypes() {
        return baseMapper.findTypes();
    }

}
